﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.Repository;
using System.Windows.Controls.DataVisualization.Charting;

namespace FRL.DebtChased.ClientEditor
{

	/// <summary>
	/// Declaration of ClientStatsCtrl class
	/// Control for configuring statistics report
	/// and which fields are included in the client
	/// report
	/// </summary>
	public partial class ClientStatsCtrl : UserControl
	{

		/////////////////////////////////////////////////////////////
		// Nested classes

		/// <summary>
		/// Nested class for holding statistical record
		/// displayed in pie chart
		/// </summary>
		public class StatRecord
		{

			/////////////////////////////////////////////////////////
			// Attributes

			private string m_strSection;
			public string Section
			{
				get { return m_strSection; }
			}

			private double m_dblTotal;
			public double Total
			{
				get { return m_dblTotal; }
			}

			/////////////////////////////////////////////////////////
			// Construction

			public StatRecord(string strSection, double dblTotal)
			{

				// Initialize member variables
				m_strSection = strSection;
				m_dblTotal = dblTotal;

			}

		}

		/////////////////////////////////////////////////////////////
		// Attributes

		private List<StatRecord> m_stats = new List<StatRecord>();

		/////////////////////////////////////////////////////////////
		// Construction

		public ClientStatsCtrl()
		{

			// Load xaml
			InitializeComponent();

			// Set controls - Stats Type
			ComboBoxObject.LoadFromEnumeration(cboStatsType, typeof(Definitions.eClientStatsType));
			cboStatsType.SelectedIndex = 0;

			// Refresh the data
			_refreshStats();

		}

		/////////////////////////////////////////////////////////////
		// Event Handlers

		private void butEmailFrequency_Click(object sender, RoutedEventArgs e)
		{

			// TODO
			// Insert frequency editing control developed in ChaseWorkspace plugin.

		}

		private void butRefresh_Click(object sender, RoutedEventArgs e)
		{

			// Refresh the data
			_refreshStats();

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _refreshStats()
		{

			// Generate random data
			Random rnd = new Random();

			// Load the stats (use fake data for display)
			m_stats = new List<StatRecord>();
			m_stats.Add(new StatRecord("Chase", rnd.Next(2,30)));
			m_stats.Add(new StatRecord("Query", rnd.Next(2, 30)));
			m_stats.Add(new StatRecord("Copy Invoice", rnd.Next(2, 30)));
			m_stats.Add(new StatRecord("Expected", rnd.Next(2, 30)));
			m_stats.Add(new StatRecord("LBA", rnd.Next(2, 30)));
			m_stats.Add(new StatRecord("Legal", rnd.Next(2, 30)));

			// Bind to series
			PieSeries pieSeries = chart.Series[0] as PieSeries;
			pieSeries.ItemsSource = m_stats;

		}

	}

}
